package com.yic.module.mes.dal.mysql.plan;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.mes.dal.dataobject.plan.PlanDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.mes.controller.admin.plan.vo.*;

/**
 * 生产计划 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface PlanMapper extends BaseMapperX<PlanDO> {

    default PageResult<PlanDO> selectPage(PlanPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PlanDO>()
                .likeIfPresent(PlanDO::getCode, reqVO.getCode())
                .eqIfPresent(PlanDO::getType, reqVO.getType())
                .eqIfPresent(PlanDO::getItemProduceId, reqVO.getItemProduceId())
                .eqIfPresent(PlanDO::getFactoryId, reqVO.getFactoryId())
                .eqIfPresent(PlanDO::getWorkshopId, reqVO.getWorkshopId())
                .eqIfPresent(PlanDO::getEmergent, reqVO.getEmergent())
                .eqIfPresent(PlanDO::getBatchNo, reqVO.getBatchNo())
                .betweenIfPresent(PlanDO::getPlanStartTime, reqVO.getPlanStartTime())
                .betweenIfPresent(PlanDO::getPlanCompleteTime, reqVO.getPlanCompleteTime())
                .eqIfPresent(PlanDO::getStatus, reqVO.getStatus())
                .orderByDesc(PlanDO::getId));
    }

    default List<PlanDO> selectList(PlanExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<PlanDO>()
                .likeIfPresent(PlanDO::getCode, reqVO.getCode())
                .eqIfPresent(PlanDO::getType, reqVO.getType())
                .eqIfPresent(PlanDO::getItemProduceId, reqVO.getItemProduceId())
                .eqIfPresent(PlanDO::getFactoryId, reqVO.getFactoryId())
                .eqIfPresent(PlanDO::getWorkshopId, reqVO.getWorkshopId())
                .eqIfPresent(PlanDO::getEmergent, reqVO.getEmergent())
                .eqIfPresent(PlanDO::getBatchNo, reqVO.getBatchNo())
                .betweenIfPresent(PlanDO::getPlanStartTime, reqVO.getPlanStartTime())
                .betweenIfPresent(PlanDO::getPlanCompleteTime, reqVO.getPlanCompleteTime())
                .eqIfPresent(PlanDO::getStatus, reqVO.getStatus())
                .orderByDesc(PlanDO::getId));
    }

    default PlanDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<PlanDO>()
                .eq(PlanDO::getCode, code));
    }

    default PlanDO selectOneByItemProduceId(Long id) {
        return selectOne(new LambdaQueryWrapperX<PlanDO>()
                .eq(PlanDO::getItemProduceId, id)
                .last("limit 1"));
    }

    default int deleteByCode(String code) {
        return delete(new LambdaQueryWrapperX<PlanDO>()
                .eq(PlanDO::getCode, code));
    }
}
